package pokerStat.poker;

import java.sql.SQLException;

import neuroPoker.PokerLogicKI.PokerLogicSpieler;
import neuroPoker.netze.PokerInputSit;
import neuroPoker.poker.SimuTisch;
import neuroPoker.poker.Enums.Actions;
import neuroPoker.poker.Enums.Stages;
import pokerStat.sit.SitClassFinder;
import pokerStat.sit.SituationFinderPB;

public class PStatSpieler extends PokerLogicSpieler {
	SituationFinderPB sitFind;

	public PStatSpieler(String name, int stack, SimuTisch tisch) {
		super(tisch, name, stack);
		try {
			sitFind = new SituationFinderPB();
		} catch (SQLException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	@Override
	public Actions getAction(boolean canRaise) {
		Stages stage = tisch.getSpiel().getStage();
		/** betround ermitteln **/
		int br = 0;
		if (stage == Stages.preFlop) {
			br = preflopActions.size();
		} else if (stage == Stages.flop) {
			br = 3 + flopActions.size();
		} else if (stage == Stages.turn) {
			br = 7 + turnActions.size();
		} else {
			br = 11 + riverActions.size();
		}

		// nur preflop (br=0 und br=1) mit PokerStat
		if (br < 2) {
			try {
				Class<? extends PokerInputSit> sitClass = SitClassFinder
						.getSitClass(br);

				PokerInputSit sit = (PokerInputSit) sitClass.getConstructors()[0]
						.newInstance(tisch, this);

				double[] evs = sitFind.findSimilarSitEVs(sit, karten);

				if (evs[1] > 0 && evs[1] > evs[2])
					return Actions.checkCall;

				if (evs[2] > 0)
					return Actions.raise;

				if (evs[1] < 0 && evs[2] < 0)
					return Actions.fold;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		System.out.println("PStatSpieler: No dec. through PStat -> using PL");

		return super.getAction(canRaise);
	}

}
